* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: #f8f9fa;
  height: 100vh;
  overflow: hidden;
}

.app-container {
  width: 100%;
  height: 100vh;
  display: flex;
  background-color: #ffffff;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

/* 左侧边栏样式 - 类似Ollama */
.sidebar {
  width: 280px;
  background: linear-gradient(180deg, #2c3e50 0%, #34495e 100%);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e1e8ed;
  position: relative;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.1);
}

.new-chat-btn {
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.new-chat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.chat-history::-webkit-scrollbar {
  width: 4px;
}

.chat-history::-webkit-scrollbar-track {
  background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.chat-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #ecf0f1;
  font-size: 13px;
  line-height: 1.4;
  position: relative;
  overflow: hidden;
}

.chat-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(2px);
}

.chat-item.active {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.3), rgba(118, 75, 162, 0.3));
  border-color: rgba(102, 126, 234, 0.5);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.chat-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, #667eea, #764ba2);
}

.chat-title {
  font-weight: 500;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
}

/* 主内容区样式 */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
}

.main-header {
  padding: 20px 24px;
  border-bottom: 1px solid #e1e8ed;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.main-title {
  font-size: 20px;
  font-weight: 600;
  color: #2c3e50;
  margin: 0;
}

/* 头部按钮容器 */
.header-buttons {
  display: flex;
  gap: 10px;
}

.clear-btn, .theme-btn {
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.clear-btn {
  background: linear-gradient(135deg, #ff6b6b, #ee5a52);
  color: white;
}

.theme-btn {
  background: linear-gradient(135deg, #4b6cb7, #182848);
  color: white;
}

.clear-btn:hover:not(:disabled), .theme-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.clear-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 夜间模式样式 */
body.dark-mode {
  background-color: #1a1a1a;
}

.dark-mode .app-container {
  background-color: #1a1a1a;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.dark-mode .main-content {
  background-color: #1a1a1a;
}

.dark-mode .main-header {
  background: linear-gradient(135deg, #1a1a1a 0%, #2c2c2c 100%);
  border-bottom: 1px solid #333;
}

.dark-mode .main-title {
  color: #e1e1e1;
}

.dark-mode .chat-messages {
  background: linear-gradient(135deg, #1a1a1a 0%, #2c2c2c 50%, #1a1a1a 100%);
}

.dark-mode .empty-state {
  color: #a0a0a0;
}

.dark-mode .message-author {
  color: #e1e1e1;
}

.dark-mode .message-time {
  color: #a0a0a0;
}

.dark-mode .assistant-message .message-bubble {
  background: #2c2c2c;
  border: 1px solid #444;
  color: #e1e1e1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.dark-mode .input-area {
  background: #1a1a1a;
  border-top: 1px solid #333;
}

.dark-mode .message-input {
  background: #2c2c2c;
  border-color: #444;
  color: #e1e1e1;
}

.dark-mode .message-input:focus {
  border-color: #667eea;
  background: #333;
}

.dark-mode .markdown-content h1,
.dark-mode .markdown-content h2,
.dark-mode .markdown-content h3,
.dark-mode .markdown-content h4,
.dark-mode .markdown-content h5,
.dark-mode .markdown-content h6 {
  color: #e1e1e1;
}

.dark-mode .markdown-content pre {
  background-color: #333;
  border: 1px solid #444;
}

.dark-mode .markdown-content code {
  background-color: #333;
  color: #e1e1e1;
}

.dark-mode .markdown-content pre code {
  color: #e1e1e1;
}

.dark-mode .markdown-content .code-header {
  background: #444;
  color: #a0a0a0;
  border-bottom: 1px solid #555;
}

.dark-mode .markdown-content blockquote {
  color: #a0a0a0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 50%, #f8f9fa 100%);
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #6c757d;
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-title {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 8px;
}

.empty-description {
  font-size: 14px;
  opacity: 0.7;
}

/* 消息样式 */
.message-container {
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.message {
  display: flex;
  gap: 12px;
  width: 100%;
}

.message-spacer {
  flex: 1;
  min-width: 20px;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-avatar {
  background: linear-gradient(135deg, #667eea, #764ba2);
}

.assistant-avatar {
  background: linear-gradient(135deg, #16bb60, hsl(249, 75%, 36%));
}

.message-content {
  flex: 0 1 auto;
  max-width: 80%; /* 增加消息气泡的最大宽度，显示更多文字 */
  min-width: 0; /* 确保内容可以收缩 */
}

@media (max-width: 768px) {
  .message-content {
    max-width: 85%; /* 在移动设备上允许更宽的气泡 */
  }
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.user-message .message-header {
  flex-direction: row-reverse;
}

.message-author {
  font-weight: 600;
  font-size: 14px;
  color: #2c3e50;
}

.message-time {
  font-size: 12px;
  color: #6c757d;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 10px;
  position: relative;
  word-wrap: break-word;
  line-height: 1.4;
  width: 100%; /* 确保气泡填充内容区域 */
  box-sizing: border-box;
  max-width: 100%; /* 确保不会超出父容器 */
  overflow: hidden; /* 防止内容溢出 */
}

.user-message .message-bubble {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border-bottom-right-radius: 4px;
}

.assistant-message .message-bubble {
  background: #ffffff;
  border: 1px solid #e1e8ed;
  color: #2c3e50;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* 输入区域样式 */
.input-area {
  padding: 20px 24px;
  border-top: 1px solid #e1e8ed;
  background: #ffffff;
}

.input-container {
  display: flex;
  gap: 12px;
  align-items: center;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

.message-input {
  width: 100%;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 16px;
  border: 2px solid #e1e8ed;
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: all 0.2s ease;
  background: #f8f9fa;
}

.message-input:focus {
  border-color: #667eea;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.send-btn {
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  color: white;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 80px;
  justify-content: center;
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* 发送按钮加载状态样式 */
.send-btn.loading {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  padding: 0;
  animation: pulse 1.5s infinite;
}

.send-btn.loading .loading-square {
  width: 14px;
  height: 14px;
  background-color: white;
  border-radius: 2px;
  animation: rotate 1.5s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(102, 126, 234, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(102, 126, 234, 0);
  }
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Markdown 内容样式 */
.markdown-content {
  line-height: 1.5;
  font-size: 15px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
  margin-top: 1.5em;
  margin-bottom: 0.8em;
  font-weight: 600;
  color: #2c3e50;
}

.markdown-content h1 { font-size: 1.5em; }
.markdown-content h2 { font-size: 1.3em; }
.markdown-content h3 { font-size: 1.1em; }

.markdown-content p {
  margin-bottom: 1em;
}

.markdown-content pre {
  background-color: #f8f9fa;
  border-radius: 8px;
  padding: 0;
  margin: 1em 0;
  border: 1px solid #e1e8ed;
  overflow: hidden;
  width: 100%; /* 确保代码块使用全部可用宽度 */
  box-sizing: border-box;
  max-width: 100%; /* 确保代码块不会超出消息气泡 */
}

.markdown-content code {
  background-color: #f1f3f4;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: #2c3e50;
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
}

.markdown-content pre code {
  background: none;
  padding: 12px;
  color: #2c3e50;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  word-wrap: normal;
  tab-size: 4;
  hyphens: none;
  display: block;
  overflow-x: auto;
  line-height: 1.5;
  border-radius: 0;
  max-width: 100%; /* 确保代码不会超出容器 */
  box-sizing: border-box;
}

/* 代码块包装容器 */
.markdown-content .code-block-wrapper {
  width: 100%;
  margin: 1em 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e1e8ed;
  max-width: 100%; /* 确保代码块包装器不会超出消息气泡 */
  box-sizing: border-box;
}

/* 代码块语言标签 */
.markdown-content .code-header {
  background: #e8eaed;
  color: #5f6368;
  padding: 5px 12px;
  font-size: 12px;
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
  border-bottom: 1px solid #e1e8ed;
  text-align: right;
}

/* 调整代码块内的pre标签样式 */
.markdown-content .code-block-wrapper pre {
  margin: 0;
  border: none;
  border-radius: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.markdown-content blockquote {
  border-left: 4px solid #667eea;
  padding-left: 16px;
  margin: 1em 0;
  color: #6c757d;
  font-style: italic;
}

.markdown-content ul,
.markdown-content ol {
  padding-left: 1.5em;
  margin-bottom: 1em;
}

.markdown-content li {
  margin-bottom: 0.5em;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .sidebar {
    width: 260px;
    position: absolute;
    left: -260px;
    z-index: 1000;
    transition: left 0.3s ease;
  }
  
  .sidebar.show {
    left: 0;
  }
  
  .main-content {
    width: 100%;
  }
  
  .chat-messages {
    padding: 16px;
  }
  
  .input-area {
    padding: 16px;
  }
}

/* 加载动画 */
.loading-dots {
  display: inline-flex;
  gap: 2px;
}

.loading-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: loading 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes loading {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* 流式打字效果 */
.typing-effect {
  display: inline-block;
  vertical-align: bottom;
  width: 0.5em;
  height: 1.2em;
  background-color: currentColor;
  margin-left: 2px;
  animation: typing-cursor 0.8s infinite;
}

@keyframes typing-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}